package org.lizar.util.pager;

import java.util.List;

public class PageData<JAVA_BEAN> {
	private int current_page;
	
	private int total;
	
	private List<JAVA_BEAN> data;
	
	private int size;

	public PageData(int current_page,int total,int size,List<JAVA_BEAN> data){
		this.current_page=current_page;
		this.total=total;
		this.data=data;
		this.size=size;
	}
	
	public int getStart(){
		int start=(current_page-1)*size;
		if(start<0)return 0;
		return start;
	}
	
	public int getPageFrom(){
		if(getMax_page()>10){
			if(this.current_page>4){
				return current_page-2;
			}
			return 1;
		}
		return 1;
	}
	
	public int getPageTo(){
		if(getMax_page()>10){
			if(this.current_page>getMax_page()-5){
				return current_page+2;
			}
			return getMax_page();
		}
		return getMax_page();
	}
	
	public int getMax_page(){
		if(total<=size)return 1;
		int rest=total%size;
		if(rest==0)return total/size;
		return (total/size)+1;
	}
	
	public int getCurrent_page() {
		return current_page;
	}

	public void setCurrent_page(int current_page) {
		this.current_page = current_page;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public List<JAVA_BEAN> getData() {
		return data;
	}

	public void setData(List<JAVA_BEAN> data) {
		this.data = data;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}
	
	
	
}
